
package com.sskj;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import com.sskj.core.repository.impl.DefaultRepositoryFactoryBean;
import com.sskj.core.web.filter.LoginRedirectFilter;

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAutoConfiguration
@ComponentScan(basePackages = { "com.sskj" })
@EnableJpaRepositories(
		repositoryFactoryBeanClass = DefaultRepositoryFactoryBean.class,
		basePackages = { "com.sskj" })
@EnableCaching
// @EnableSwagger2
@EntityScan({ "com.sskj" })
public class SingleApplicationMain extends SpringBootServletInitializer {

	static final Log logger = LogFactory.getLog(SingleApplicationMain.class);

	@Override
	protected SpringApplicationBuilder configure(
			SpringApplicationBuilder application) {

		return application.sources(SingleApplicationMain.class);
	}

	public static void main(String[] args) throws Exception {

		SpringApplication.run(SingleApplicationMain.class, args);
	}

	@Bean
	public FilterRegistrationBean loginRedirectFilterRegistration() {

		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new LoginRedirectFilter());
		registration.addUrlPatterns("/login");
		registration.addUrlPatterns("/login.html");
		registration.setName("loginRedirectFilter");
		registration.setOrder(-1000);
		return registration;
	}
}
